<template>
    <a-modal
            title="新增"
            :visible="visible"
            width="1200px"
            @ok="handleOk"
            :maskClosable="false"
            :confirmLoading="confirmLoading"
            @cancel="handleCancel"
    >
        <a-form-model ref="form" :model="form" :rules="rules">
            
                <a-descriptions bordered :column="2">
                
                    <a-descriptions-item label="分配产品" :span="2">
                        <a-form-model-item>
                            <a-select v-model="form.serviceProductCode" placeholder="请选择分配产品"  showSearch allowClear>
                                <a-select-option
                                 v-for="(item,index) in productList" 
                                 :key="index"
                                 :value="item.serviceProductCode">
                                    {{item.advisoryBodyName}}
                                </a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-descriptions-item>

                    <a-descriptions-item label="分配顾问">
                        <a-form-model-item>
                            <a-select v-model="form.adviserCode" placeholder="请选择分配顾问"  showSearch allowClear>
                                <a-select-option
                                 v-for="(item,index) in advisoryList" 
                                 :key="index"
                                 :value="item.adviserCode">
                                    {{item.adviserName}}
                                </a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-descriptions-item>


                </a-descriptions>
         

            
        </a-form-model>
    </a-modal>
</template>

<script>
    import {demandBaseAllocation,productList,advisoryList} from '@/assets/api/new'
   
    export default {
        name: "xlForm",
        data() {
            return {
                tableTitle: '',
                visible: false,
                confirmLoading: false,
                form: {
                    serviceProductCode:'', 
                    adviserCode:''
                },
                productList:[],
                advisoryList:[],
                
                formFile: {},
                rules: {},
            }
        },
        created(){
            productList({
                param: {}
            })
            .then(res => {
                console.log(res,111)
                this.productList = res.result
            })
            advisoryList({
                param:{}
            })
            .then(res => {
                console.log(res,222)
                this.advisoryList = res.result
            })
        },
        components: {

        },
        methods: {
            handleOk() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        if(this.form.serviceProductCode != '' || this.form.adviserCode != ''){
                            demandBaseAllocation({
                                param: this.form
                            })
                                .then(result=>{
                                    this.visible = false
                                    this.confirmLoading = false
                                    this.$parent.pageOnload()
                                }).catch(_=>{
                                    this.confirmLoading = false
                                })
                        }
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            handleCancel() {
                this.visible = false
            },
            formatData() {

            },
            formatForm(form) {
                console.log(form)
                delete form.createDateTime
                delete form.modifyDateTime
                delete form.modifyBy
                delete form.createBy
                //整理字段数据 ／ 赋值 清空等
                this.form = form
                if(this.form.serviceProductCode != ''){
                    this.form.serviceProductCode = undefined
                    this.form.advisoryBodyName = undefined
                }
                if(this.form.adviserCode != ''){
                    this.form.adviserCode = undefined
                    this.form.adviserName = undefined
                }
                
                
             

            }
        }
    }
</script>

<style scoped lang="less">
    /deep/ .ant-form-item {
        margin: 0;
    }

    /deep/ .ant-input-number {
        width: 100%;
    }

    .xl-dateRange {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .ant-checkbox-group {
        display: flex;
        flex-wrap: wrap;

        .xl-checkbox {
            display: flex;
            align-items: center;

            /deep/ span:nth-child(2):not(.ant-checkbox-inner) {
                display: flex;
                justify-content: space-between;
                white-space: pre;
            }
        }
    }

    .ant-card {
        margin-bottom: 10px;

        .ant-select {
            min-width: 300px;
        }
    }

    .descriptions {
        /deep/ .ant-descriptions-item-content {
            width: 50%;
        }
    }
</style>
